<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="css/base.css">
	<title>Document</title>
	<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$("span").parentsUntil("div").css({"color":"red","border":"2px solid red"});

			$("div").find("span").css({"color":"blue","border":"2px solid blue"})
		});
	</script>
</head>
<body>
	<div class="ancestors">
		<div style="width: 500px;">div (曾祖父)
			<ul> ul (祖父)
				<li> li (直接父)
					<span>span</span>
				</li>
			</ul>
		</div>
		<div style="width: 500px;">div (祖父)
			<p> p (直接父)
				<span>span</span>
			</p>
		</div>
	</div>
</body>
</html>